﻿var textbox = (function () {
    function cinit(t) {
        if (t.field == "REMARK")
            t.multiline = true;
        var html = chtml(t);
        $("#" + t.applyTo).append(html);
        t.tb = ctextbox(t, html);
    }
    function chtml(t) {
        var html = "";
        var span = t.fz + '<span>' + t.title + '</span><br>';
        for (var i in t.box) {
            var v = t.box[i];
            if (v != null) {
                if ((i == 'disabled' || i == 'readonly') && v === true)
                    html += ' ' + i + '="' + v + '"';
                if (i != 'disabled' && i != 'readonly')
                    html += ' ' + i + '="' + v + '"';
            }
        }
        html = span + '<input id="' + t.field + '" style="width:100%;height:30px"' + html + ">" + t.hz;
        return html;
    }
    function ctextbox(t, html) {
        //$(html).textbox(t.box);
        $("#" + t.field).textbox({
            onChange: function (newValue, oldValue) {
                t.onChange(newValue, oldValue);
            },
            onResize: function (width, height) {
                t.onResize(width, height);
            },
            onClickButton: function () {
                t.onClickButton();
            },
            onClickIcon: function (index) {
                t.onClickIcon(index);
            }
        });
        return $("#" + t.field);
    }
    return {
        parent: null,
        applyTo: "",
        title: "",
        field: "",
        fz: "<li>",
        hz: "</li>",
        box: {
            disabled: false,
            readonly: false,
            iconCls: null,
            iconAlign: "right",
            iconWidth: 18,
            buttonText: null,
            buttonIcon: null,
            buttonAlign: "right",
            multiline: false
        },
        init: function () {
            cinit(this);
        },
        html: function () {
            return chtml(this);
        },
        readonly: function (only) {
            this.tb.textbox('readonly', only);
        },
        clear: function () {
            this.tb.textbox('clear');
        },
        initValue: function (value) {
            this.tb.textbox('initValue', value);
        },
        setText: function (text) {
            this.tb.textbox('setText', text);
        },
        getText: function () {
            return this.tb.textbox('getText');
        },
        setValue: function (value) {
            this.tb.textbox('setValue', value);
        },
        getValue: function () {
            return this.tb.textbox('getValue');
        },
        disable: function () {
            this.tb.textbox('disable');
        },
        enable: function () {
            this.tb.textbox('enable');
        },
        validate: function () { },
        onChange: function (newValue, oldValue) { },
        onResize: function (width, height) { },
        onClickButton: function () { },
        onClickIcon: function (index) { }
    }
})